#pragma once

#include "Base/Tests/Test.Application.h"

#undef  APP_NAME
#define APP_NAME	TestExternalDir
#undef  APP_BASE
#define APP_BASE	TestApp


class APP_NAME : public APP_BASE
{
public:
	APP_NAME (IPlatform *platform, EDevice::type deviceType) :
		APP_BASE( platform, deviceType )
	{
	}

	void Output (uni_c_string str)
	{
		ESS()->GetApplication()->GetPlatform()->ShowNotification( str.cstr(), true );
	}

	void OnEnter () override
	{
		string	cd;
		ESS()->GetFileSystem()->GetCurrentDirectory( cd );
		Output( ("current directory: " + cd).cstr() );

		// C:\\Projects\\CPP\\p024_sdl_engine\\src\\Engine\\_data/
		const char		newdir[] = "newdir/1/2/3/4/5/6";

		const string	dir = StringUtils::AddToPath( ESS()->GetApplication()->GetPlatform()->GetExternalPath(),
												 (uni_c_string) newdir );
		

		CHECK_ERR( ESS()->GetFileSystem()->CreateDirectories( dir ), );
		Output( dir.cstr() );

		CHECK_ERR( ESS()->GetFileSystem()->IsDirectoryExist( dir ), );

		CHECK_ERR( ESS()->GetFileSystem()->SetCurrentDirectory( dir ), );

		WFilePtr	file;

		CHECK_ERR( ESS()->GetFileSystem()->CreateFile( "text.txt", file ), );

		const char	buf[] = "external directory test";

		file->Write( buf );

		file = null;

		DEBUG_CONSOLE( "delete dir test" );
		
		CHECK_ERR( ESS()->GetFileSystem()->SetCurrentDirectory( ESS()->GetApplication()->GetPlatform()->GetExternalPath() ), );

		CHECK_ERR( ESS()->GetFileSystem()->DeleteDirectory( "newdir/1" ), );
		
		DEBUG_CONSOLE( "test completed" );
	}
};